package ProjectTeam39.Domains;
import java.io.*;
import java.util.*;
//import java.util.Scanner;

public class Employees
{
	
	//should keep a list of clients,
	//possibly in XML form.
	//for now it will be writing to a .txt file created
	//in the directory where the .java files are
	//(maybe in it's own folder?)
	protected FileOutputStream writer;
	protected PrintStream out;
	protected String filename = "employees.txt";
	protected String fullfilepath;
	protected UserList theUsers;
	protected String dir;
	protected String sep;
	protected ArrayList<Doctor> theDoctors;
	protected ArrayList<Nurse> theNurses;
	protected ArrayList<SystemAdmin> theAdmins;
	
	public Employees(UserList theUsers)
	{
		this.theUsers = theUsers;
	
		theDoctors = new ArrayList<Doctor>();
		Doctor testDoctor = new Doctor("Doctor Who", "doctorwho" ,"password", Long.parseLong("478678994"), "Where Doctor Who Lives",
				null, theUsers, "womanizer");
		this.createDoctor(testDoctor);
					
		theNurses = new ArrayList<Nurse>();
		Nurse testNurse = new Nurse("Nurse Joy", "nursejoy", "password", Long.parseLong("3333333333"), "Pokemon Island", null, theUsers);
		this.createNurse(testNurse);
					
		theAdmins = new ArrayList<SystemAdmin>();
		SystemAdmin testAdmin = new SystemAdmin("GLADoS", "glados", "password", Long.parseLong("3333333333"), "Aperature Science Laboratories", null, theUsers);
		this.createAdmin(testAdmin);					
	}
	public ArrayList<Doctor> getDoctors(){
		return theDoctors;
	}
	
	public ArrayList<Nurse> getNurses(){
		return theNurses;
	}
	
	public ArrayList<SystemAdmin> getAdmins(){
		return theAdmins;
	}
	
	//Array list that holds patients, functions that can index into each
	//patient in that list and get name/user/pass
	boolean createDoctor(Doctor theDoctor)
	{
		try
		{
			theDoctors.add(theDoctor);
		}
		catch (Exception e)
		{
			return false;
		}
		return true;
		
	}
	
	Doctor getDoctor(String name)
	{
		boolean found = false;
		int index = 0;
		for(int i=0;i<theDoctors.size();i++)
		{
			while(found == false)
			{
				if(theDoctors.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
					index = i;
				}
			}
		}
		if(found == true)
		{
			return theDoctors.get(index);
		}
		else
		{
			return null;
		}
		
	}
	
	boolean findDoctor(String name) //returns index of patient if found
	{
		boolean found = false;
		for(int i=0;i<theDoctors.size();i++)
		{
			while(found == false)
			{
				if(theDoctors.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
				}
			}
		}
		if(found == true)
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}
	
	int findDoctorIndex(String name) //returns index of patient if found
	{
		boolean found = false;
		int index = 0;
		for(int i=0;i<theDoctors.size();i++)
		{
			while(found == false)
			{
				if(theDoctors.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
					index = i;
				}
			}
		}
		if(found == true)
		{
			return index;
		}
		else
		{
			return index; //may need to change this
		}
		
	}
	
	boolean deleteDoctor(String name)
	{
		try{
			if(findDoctor(name) == true)
			{
				theDoctors.remove(findDoctorIndex(name));
			}
			if(findDoctor(name) == false)
			{
				return false;
			}
		}
		catch(Exception e)
		{
			return false;
		}
		return true;
		
	}
	
	////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////
	
	
	boolean createNurse(Nurse theNurse)
	{
		try
		{
			theNurses.add(theNurse);
		}
		catch (Exception e)
		{
			return false;
		}
		return true;
		
		
	}
	
	Nurse getNurse(String name)
	{
		boolean found = false;
		int index = 0;
		for(int i=0;i<theNurses.size();i++)
		{
			while(found == false)
			{
				if(theNurses.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
					index = i;
				}
			}
		}
		if(found == true)
		{
			return theNurses.get(index);
		}
		else
		{
			return null;
		}
		
	}
	
	boolean findNurse(String name) //returns index of patient if found
	{
		boolean found = false;
		for(int i=0;i<theNurses.size();i++)
		{
			while(found == false)
			{
				if(theNurses.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
				}
			}
		}
		if(found == true)
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}
	
	int findNurseIndex(String name) //returns index of patient if found
	{
		boolean found = false;
		int index = 0;
		for(int i=0;i<theNurses.size();i++)
		{
			while(found == false)
			{
				if(theNurses.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
					index = i;
				}
			}
		}
		if(found == true)
		{
			return index;
		}
		else
		{
			return index; //may need to change this
		}
		
	}
	
	boolean deleteNurse(String name)
	{
		try{
			if(findNurse(name) == true)
			{
				theNurses.remove(findNurseIndex(name));
			}
			if(findNurse(name) == false)
			{
				return false;
			}
		}
		catch(Exception e)
		{
			return false;
		}
		return true;
		
	}
	
	
////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////
	
	
	boolean createAdmin(SystemAdmin theAdmin)
	{
		try
		{
			theAdmins.add(theAdmin);
		}
		catch (Exception e)
		{
			return false;
		}
		return true;
		
		
	}
	
	SystemAdmin getAdmin(String name)
	{
		boolean found = false;
		int index = 0;
		for(int i=0;i<theAdmins.size();i++)
		{
			while(found == false)
			{
				if(theAdmins.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
					index = i;
				}
			}
		}
		if(found == true)
		{
			return theAdmins.get(index);
		}
		else
		{
			return null;
		}
		
	}
	
	boolean findAdmin(String name) //returns index of patient if found
	{
		boolean found = false;
		for(int i=0;i<theAdmins.size();i++)
		{
			while(found == false)
			{
				if(theAdmins.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
				}
			}
		}
		if(found == true)
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}
	
	int findAdminIndex(String name) //returns index of patient if found
	{
		boolean found = false;
		int index = 0;
		for(int i=0;i<theAdmins.size();i++)
		{
			while(found == false)
			{
				if(theAdmins.get(i).getName().equalsIgnoreCase(name))
				{
					found = true;
					index = i;
				}
			}
		}
		if(found == true)
		{
			return index;
		}
		else
		{
			return index; //may need to change this
		}
		
	}
	
	boolean deleteAdmin(String name)
	{
		try{
			if(findAdmin(name) == true)
			{
				theAdmins.remove(findAdminIndex(name));
			}
			if(findAdmin(name) == false)
			{
				return false;
			}
		}
		catch(Exception e)
		{
			return false;
		}
		return true;
		
	}
}
